package com.yyj.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.common.utils.Page;
import com.yyj.dao.GoodsDao;
import com.yyj.domain.Goods;
import com.yyj.service.GoodsService;

@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {
	@Autowired
	private GoodsDao goodsDao;

//չʾ��Ʒ
	@Override
	public List<Goods> getAllGoods() {
		return goodsDao.getAllGoods();
	}

	@Override
	public List<Goods> getAllSelectGoods(String name) {
		return goodsDao.getAllSelectGoods(name);
	}

	@Override
	public Goods getGoodsdescribe(String goods_id) {
		return goodsDao.getGoodsdescribe(goods_id);
	}

	@Override
	public Goods getGoods(int goods_id) {
		return goodsDao.getGoods(goods_id);
	}

	@Override
	public Page<Goods> findGoodsList(Integer page, Integer rows, String goods_name, String description) {
		// 创建客户对象
		Goods goods = new Goods();
		// 判断客户名称
		if (StringUtils.isNotBlank(goods_name)) {
			goods.setName(goods_name);
		}

		// 判断客户所属行业
		if (StringUtils.isNotBlank(description)) {
			goods.setDescription(description);
		}

		// 当前页
		goods.setStart((page - 1) * rows);
		// 每页数
		goods.setRows(rows);
		// 查询客户列表
		List<Goods> goodss = goodsDao.selectGoodsList(goods);
		// 查询客户列表总记录数
		Integer count = goodsDao.selectGoodsListCount(goods);
		// 创建Page返回对象
		Page<Goods> result = new Page<>();
		result.setPage(page);
		result.setRows(goodss);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}

	@Override
	public int deleteGoods(int goods_id) {
		return goodsDao.deleteGoods(goods_id);
	}

	@Override
	public int updateGoods(Goods goods) {
		return goodsDao.updateGoods(goods);
	}

	@Override
	public int createGoods(Goods goods) {
		return goodsDao.createGoods(goods);
	}

}
